<?php
include_once 'BaseS.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/application/model/LogUserActionM.php';
include_once $_SERVER ['DOCUMENT_ROOT'].BASE_PROJECT_PATH.'/library/util/Util.php';

class LogUserActionS extends BaseS {
	
	public function __construct() {
		parent::__construct ();
		parent::setTarget ( $this );
	}

	public function queryTable(){
		
		$result = array("sl"=>"1", "di"=>"0", "ti"=>"", "msg"=>"");
		$dao = new LogUserActionM();
		$obj = $this->getRequest("datas");
		
		$startPage = ($obj['page']-1) * $obj['pageRow']; 
		$searchStr = "";
		$startDate = $obj['searchData']['dateStart'] ? $obj['searchData']['dateStart'] : "1990-01-01" ;
		$endDate = $obj['searchData']['dateEnd'] ? $obj['searchData']['dateEnd'] : "3999-12-31" ;
		$searchStr .= " and date_format(date_modify, '%Y-%m-%d') between '$startDate' and '$endDate' ";
	
		if( $obj['searchData']['userName'] != ""){$searchStr .= " and user_id in (select id from user where name like '%".$obj["searchData"]["userName"]."%') ";} 
		if( $obj['searchData']['actionArea'] != "0"){$searchStr .= " and action_area = '". $obj['searchData']['actionArea']."'  ";}
		if( $obj['searchData']['actionType'] != 0){$searchStr .= " and action_type = ". $obj['searchData']['actionType']."  ";}

		$result['data'] = $dao->queryTable($obj['orderData'], $startPage, $obj['pageRow'], $searchStr);
		
		if($result["data"] == null){
			$result["di"] = "1";
			$result["ti"] = "系統異常";
			$result["msg"] = "資料庫無法連接！";
		}
		
		if($result["data"]['count'] == 0){
			$result["di"] = "1";
			$result["ti"] = "查無資料";
			$result["msg"] = "資料庫沒有相關資料！";
		}
		
		echo Util::toJson($result); 
	}
	
	public function queryArea(){
		$result = array("sl"=>"1", "di"=>"0", "ti"=>"", "msg"=>"");
		$dao = new LogUserActionM();
		$result['data'] = $dao->queryArea();
		if($result["data"] == null){
			$result["di"] = "1";
			$result["ti"] = "查無資料";
			$result["msg"] = "資料庫沒有相關資料！";
		}
		echo Util::toJson($result);
	}
	
}

if (isset($_GET ["action"])) {
	$service = new LogUserActionS ();
	$service->__call ( $_GET ["action"], null );
} 
?>